package com.bsj.power.common.file.log;

import com.bsj.writeFile.WriteAndReadFileAction;
import com.bsj.writeFile.def.DataVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import redis.clients.bsj.JedisClusterBSJ;

import java.util.List;

/**
 * @author yinhao
 * @version 1.0
 * @description 操作日志写
 * @date 2024/6/3
 */
@Slf4j
@Profile({"power-master-system", "power-module-job", "power-module-video"})
@Component
public class OperateLogWriteAndRead {
    private WriteAndReadFileAction fileAction;

    @Value("${file.operateLog}")
    private String filePath;

    @Autowired
    private JedisClusterBSJ jedisClusterBSJ;

    public void start(String name) {
        log.info("filePath:" + filePath);
        fileAction = new WriteAndReadFileAction(jedisClusterBSJ, filePath);
        fileAction.settingInterval(30);
        fileAction.start(name);
    }

    public void stop() {
        if (fileAction != null) {
            fileAction.stop();
        }
    }

    public List<DataVo> readData(String id, long start, long end) {
        return fileAction.readVoAll(id, start, end);
    }
}
